<template>
  <div id="app">
    <!-- 头部区域 -->
    <v-header :seller="this.seller"></v-header>
    <!-- 导航区域 -->
    <div class="tab border-1px">
      <ul>
        <router-link to="/goods" tag="li">商品</router-link>
        <router-link to="/ratings" tag="li">评价</router-link>
        <router-link to="/seller" tag="li">商家</router-link>
      </ul>
    </div>
    <!-- 内容区域 -->
    <keep-alive>
      <!-- 因为子组件使用better-scroll，要通过seller计算width属性，
      v-if="seller.name"确保seller已经获取完毕后再开始渲染子组件， -->
      <router-view v-if="seller.name" :seller="seller"></router-view>
    </keep-alive>
    <shopcar :minPrice="seller.minPrice" :deliveryPrice="seller.deliveryPrice"></shopcar>
  </div>
</template>
<script>
// 所有的组件都以v-开头，表示是vue的组件，避免冲突
import header from "./components/header/header";
import shopcar from "./components/shopcar/shopcar";
import { urlParse } from "./common/js/util.js";
export default {
  name: "App",
  data() {
    return {
      seller: {
        id: (() => {
          let queryParam = urlParse();
          return queryParam.id;
        })()
      }
    };
  },
  methods: {
    getHeader() {
      this.$http.get("/api/seller?id=" + this.seller.id).then(result => {
        if (result.status === 200) {
          this.seller = Object.assign({}, this.seller, result.body.data);
        }
      });
    }
  },
  created() {
    this.getHeader();
  },
  components: {
    "v-header": header,
    shopcar
  }
};
</script>
<style lang="less">
@import "./common/css/common.less";
#app {
  height: 100%;
  overflow: hidden;
  .tab {
    height: 40px;
    width: 100%;
    .border-1px( rgba(7, 17, 27, 0.1));
    ul {
      display: flex;
      justify-content: space-around;
      li {
        flex-grow: 1;
        text-align: center;
        font-size: 14px;
        line-height: 40px;
        color: rgb(77, 85, 93);
        //为点击的tab设置高亮
        &.active {
          color: rgb(240, 20, 20);
        }
      }
    }
  }
}
</style>
